<?php


namespace app\console\service\tag;

use app\dao\goods\SupplierDao;
use app\dao\goods\TagDao;
use app\model\Supplier;
use app\model\Tag;

class TagService
{
    /**
     * @var Tag
     */
    private Tag $tag;

    public function __construct(Tag $tag)
    {
        $this->tag = $tag ;
    }

    public function create($data)
    {
        $tagDao = new TagDao();
        return $tagDao->save(['name' => $data['name']]);
    }

    public function update($name)
    {
        $tagDao = new TagDao();

        if (!empty($name)) {
            $this->tag->name = $name;
        }

        $tagDao->update($this->tag->toArray(), $this->tag->id);

        return $tagDao->getById($this->tag->id);
    }

    public function delete()
    {
        $tagDao = new TagDao();
        $tagDao->deleteById($this->tag->id);
    }

}